using System;
using Controls;
using Events;
using PrimeTween;
using TMPro;
using UnityEngine;

namespace Globals.States
{
    public class TutorialState : MonoBehaviour, IState
    {
        [SerializeField] private VoidEventChannel tutorialStartedEvent;

        [SerializeField] private PlayerController playerController;
        [SerializeField] private CanvasGroup startUi;

        [SerializeField] private TextMeshProUGUI aimText;
        [SerializeField] private TextMeshProUGUI shootText;


        private void Awake()
        {
            aimText.gameObject.SetActive(false);
            shootText.gameObject.SetActive(false);
            
            tutorialStartedEvent.Init();
        }

        public void Enter()
        {
            playerController.MoveCursorPerformed += PlayerController_MoveCursorPerformed;
            
            Tween.Alpha(startUi, 0f, 0.5f);
            aimText.gameObject.SetActive(true);
            
            tutorialStartedEvent.Raise();
        }

        public void OnUpdate()
        {
        }

        public void Exit()
        {
        }
        
        private void PlayerController_MoveCursorPerformed()
        {
            playerController.MoveCursorPerformed -= PlayerController_MoveCursorPerformed;
            playerController.ShootPerformed += PlayerController_ShootPerformed;
            
            aimText.gameObject.SetActive(false);
            shootText.gameObject.SetActive(true);
        }

        private void PlayerController_ShootPerformed()
        {
            shootText.gameObject.SetActive(false);
            
            playerController.ShootPerformed -= PlayerController_ShootPerformed;
            GameState.Instance.SwitchState(typeof(GameStartedState));
        }
    }
}
